/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.swirrel.listener;

import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelComponentListener extends AbstractSwirrelListener implements ComponentListener {

    private final MethodCall componentHiddenCall;
    private final MethodCall componentMovedCall;
    private final MethodCall componentResizedCall;
    private final MethodCall componentShownCall;

    public SwirrelComponentListener(
            MethodCall componentHiddenCall,
            MethodCall componentMovedCall,
            MethodCall componentResizedCall,
            MethodCall componentShownCall) {
        this.componentHiddenCall = componentHiddenCall;
        this.componentMovedCall = componentMovedCall;
        this.componentResizedCall = componentResizedCall;
        this.componentShownCall = componentShownCall;
        if (!checkSignature(componentHiddenCall, ComponentEvent.class)
            || !checkSignature(componentMovedCall, ComponentEvent.class)
            || !checkSignature(componentResizedCall, ComponentEvent.class)
            || !checkSignature(componentShownCall, ComponentEvent.class)) {
            throw new SwirrelException("Method must have none or one ComponentEvent argument");
        }
    }

    public void componentHidden(ComponentEvent e) {
        call(componentHiddenCall, e);
    }

    public void componentMoved(ComponentEvent e) {
        call(componentMovedCall, e);
    }

    public void componentShown(ComponentEvent e) {
        call(componentShownCall, e);
    }

    public void componentResized(ComponentEvent e) {
        call(componentResizedCall, e);
    }

}
